//
//  CustomBtn+UIButton.swift
//  weibo
//
//  Created by lucy on 2016/10/22.
//  Copyright © 2016年 com.huashengHuaSheng. All rights reserved.
//

import UIKit

extension UIButton{

    /// 自定义首页按钮
    ///
    /// - parameter setImageName:      按钮图片
    /// - parameter setBackGroundName: 按钮背景图片
    /// - parameter target:            目标
    /// - parameter action:            方法
    ///
    
    convenience init(setImageName: String, setBackGroundName: String, target: Any?, action: Selector){
    
        self.init()
        
        self.setImage(UIImage(named:setImageName), for: UIControlState.normal)
        self.setImage(UIImage(named:"\(setImageName)_highlighted"), for: UIControlState.highlighted)
        
        self.setBackgroundImage(UIImage(named:setBackGroundName), for: UIControlState.normal)
        self.setBackgroundImage(UIImage(named:"\(setBackGroundName)_highlighted"), for: UIControlState.highlighted)
    
        self.addTarget(target,action: action, for: UIControlEvents.touchUpInside)
        
        self.sizeToFit()
    
    
    }


    /// 设置 button
    ///
    /// - parameter setHighlightedImgName:  图片
    /// - parameter target:                target
    /// - parameter action:                action
    ///
    /// - returns:
    convenience init(setHighlightedImgName: String? = nil, title:  String? = nil, target: Any?, action: Selector) {
        self.init()
        // 添加点击事件
        self.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        if let img = setHighlightedImgName {
            // 设置 image
            self.setImage(UIImage(named: img), for: UIControlState.normal)
            self.setImage(UIImage(named: "\(img)_highlighted"), for: UIControlState.highlighted)
        }
        
        if let title = title {
            self.setTitle(title, for: UIControlState.normal)
            self.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
            self.setTitleColor(THEMECOLOR, for: UIControlState.highlighted)
            titleLabel?.font = UIFont.systemFont(ofSize: 14)
        }
        
        self.sizeToFit()
    }


    /// 按钮定义
    ///
    /// - parameter setBackgoundImageName: 背景颜色
    /// - parameter title:                 文字
    /// - parameter titleFont:             字号
    /// - parameter titleColor:            字颜色
    /// - parameter target:                目标
    /// - parameter action:                事件
    ///
    /// - returns: 按钮
    convenience init(setBackgoundImageName:String, title:String, titleFont: CGFloat, titleColor: UIColor, target: Any?, action: Selector){
        self.init()
        
        self.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        self.setBackgroundImage(UIImage(named:setBackgoundImageName), for: UIControlState.normal)
        self.setTitle(title, for: UIControlState.normal)
        titleLabel?.textColor = titleColor
        self.setTitleColor(titleColor, for: UIControlState.normal)
        self .sizeToFit()

    }


}























